package wjl.java.base.util;

public class StringUtil {
    public static void main( String[] args ) {
        String str = null;
    }

    public static boolean isNullStr( String... strings ) {
        if ( strings == null ){
            return true;
        }
        for ( String str : strings ){
            if ( str == null || str.isEmpty() ){
                return true;
            }
        }
        return false;
    }

    /**
     * 转义字符串
     * 
     * @param str 字符串
     * @param escapeTemplate 转义模板
     * @return
     */
    public static String escapeString( String str, EscapeTemplate escapeTemplate ) {
        if ( str == null || str.isBlank() ){
            return str;
        }
        StringBuilder sb = new StringBuilder();
        for ( int i = 0; i < str.length(); i++ ){
            char c = str.charAt( i );
            for ( char escape : escapeTemplate.getTemplate() ){
                if ( c == escape ){
                    sb.append( "\\" );
                    break;
                }
            }
            sb.append( c );
        }
        return sb.toString();
    }

    public enum EscapeTemplate {
        MYSQL(0, new char[] {'\\', '%', '_', '\''});

        int    type;
        char[] template;

        private EscapeTemplate(int type, char[] template) {
            this.type = type;
            this.template = template;
        }

        public int getType() {
            return type;
        }

        public void setType( int type ) {
            this.type = type;
        }

        public char[] getTemplate() {
            return template;
        }

        public void setTemplate( char[] template ) {
            this.template = template;
        }
    }
}


